/*
 * Copyright (c) 2018 Hitevision
 */

package tw.com.hitevision.whiteboard.android.util;

import android.content.Context;
import android.view.MotionEvent;

import tw.com.hitevision.whiteboard.android.Device;
import tw.com.hitevision.whiteboard.android.Settings;

public class TouchUtils {
    /**
     * Returns the device for a touch event.
     */
//    @Deprecated
//    public static Device getEventDevice(Context context, int pointer, TouchEvent event) {
//        if (pointer >= event.getPointerCount()) {
//            return Device.FINGER;
//        }
//
//        final Settings settings = Settings.getInstance(context);
//        final int toolType = event.getToolType(pointer);
//
//        switch (toolType) {
//            case MotionEvent.TOOL_TYPE_STYLUS: {
//                return Device.STYLUS;
//            }
//            case MotionEvent.TOOL_TYPE_ERASER: {
//                return Device.PALM;
//            }
//            case MotionEvent.TOOL_TYPE_FINGER:
//            default: {
//                return settings.getImplementRecognitionMode() == Settings.IMPLEMENT_RECOGNITION_OFF
//                        ? Device.STYLUS :Device.FINGER;
//            }
//        }
//    }

    /**
     * Returns the device for a touch event.
     */
    public static Device getEventDevice(Context context, int pointer, MotionEvent event) {
        if (pointer >= event.getPointerCount()) {
            return Device.FINGER;
        }

        final Settings settings = Settings.getInstance(context);
//        if (Props.getMainboardVersion() == Props.Mainboard.V_811) { //针对F框没有上报笔型事件修改
//            float major = event.getTouchMajor(pointer);
//            if (major < 1.3f)
//                return Device.STYLUS;
//            else if (major < 10f) {
//                return settings.getImplementRecognitionMode() == Settings.IMPLEMENT_RECOGNITION_OFF
//                        ? Device.STYLUS : Device.FINGER;
//            } else
//                return Device.PALM;
//        }else { //8386等机型不作更改
            final int toolType = event.getToolType(pointer);
            switch (toolType) {
                case MotionEvent.TOOL_TYPE_STYLUS: {
                    return Device.STYLUS;
                }
                case 5:
                case MotionEvent.TOOL_TYPE_ERASER: {
                    return Device.PALM;
                }
                case MotionEvent.TOOL_TYPE_FINGER:
                default: {
                    return settings.getImplementRecognitionMode() == Settings.IMPLEMENT_RECOGNITION_OFF
                            ? Device.STYLUS : Device.FINGER;
                }
            }
//        }
    }
    /**
     * Returns the device for a touch event.
     */
    /*public static Device getEventDevice(Context context, int pointer, MotionEvent event) {
        final Settings settings = Settings.getInstance(context);
        if (pointer >= event.getPointerCount()) {
            return settings.getCurImplementRecognitionMode() == Settings.IMPLEMENT_RECOGNITION_OFF
                    ? Device.STYLUS : Device.FINGER;
        }

        final int toolType = event.getToolType(pointer);

        switch (toolType) {
            case MotionEvent.TOOL_TYPE_STYLUS: {
                return Device.STYLUS;
            }
            case MotionEvent.TOOL_TYPE_ERASER: {
                return settings.getCurImplementRecognitionMode() == Settings.IMPLEMENT_RECOGNITION_OFF
                        ? Device.STYLUS : Device.PALM;
            }
            case MotionEvent.TOOL_TYPE_FINGER:
            default: {
                return settings.getCurImplementRecognitionMode() == Settings.IMPLEMENT_RECOGNITION_OFF
                        ? Device.STYLUS : Device.FINGER;
            }
        }
    }*/
}
